-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - botstar #16757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Components - botstar #16757
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
WalkthroughThis update introduces a comprehensive BotStar integration, adding new action and source components for sending messages and emitting events related to bots and CMS entities. The BotStar app module is fully implemented with API interaction, dynamic property loading, and pagination. Supporting test data and configuration files are also included. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant SendMessageAction
participant BotStarApp
participant BotStarAPI
User->>SendMessageAction: Trigger "Send Message" action
SendMessageAction->>BotStarApp: call sendMessage(recipientId, message)
BotStarApp->>BotStarAPI: POST /messages with recipientId, message
BotStarAPI-->>BotStarApp: API response
BotStarApp-->>SendMessageAction: Return response
SendMessageAction-->>User: Output summary and response
sequenceDiagram
participant SourceComponent
participant BotStarApp
participant BotStarAPI
participant Platform
Platform->>SourceComponent: Poll for new events
SourceComponent->>BotStarApp: listBots() / listCmsEntities() / listCmsEntityItems()
BotStarApp->>BotStarAPI: GET /bots or /cms_entities or /items
BotStarAPI-->>BotStarApp: Return data
BotStarApp-->>SourceComponent: Pass data
SourceComponent->>Platform: Emit event(s) with metadata
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (5)
components/botstar/package.json (1)
3-3: Version bump to 0.7.0
The upgrade from0.6.0to0.7.0correctly reflects the addition of new BotStar components. Please ensure that your CHANGELOG or release notes are updated to document these new features and any migration steps.components/botstar/sources/new-bot-created/new-bot-created.mjs (1)
21-27: Consider adding pagination for bot listingThe current implementation fetches all bots at once using
listBots(). While this might be sufficient if users typically have a small number of bots, consider using pagination (similar to the CMS entity items component) for better scalability if the API supports it.- async run() { - const bots = await this.botstar.listBots(); - for (const bot of bots) { - const meta = this.generateMeta(bot); - this.$emit(bot, meta); - } - }, + async run() { + const results = this.botstar.paginate({ + fn: this.botstar.listBots, + args: {}, + }); + for await (const bot of results) { + const meta = this.generateMeta(bot); + this.$emit(bot, meta); + } + },components/botstar/sources/new-cms-entity-created/new-cms-entity-created.mjs (2)
37-40: Consider explaining the reverse() usageThe code uses
entities.reverse()before iterating, which appears to process newer entities first. Consider adding a comment explaining this choice for clarity:- for (const entity of entities.reverse()) { + // Process newest entities first + for (const entity of entities.reverse()) {
30-41: Consider adding pagination for entity listingSimilar to the bot listing component, consider using pagination for better scalability if the API supports it and if users might have a large number of CMS entities.
- async run() { - const entities = await this.botstar.listCmsEntities({ - botId: this.botId, - }); - if (!entities?.length) { - return; - } - for (const entity of entities.reverse()) { - const meta = this.generateMeta(entity); - this.$emit(entity, meta); - } - }, + async run() { + const results = this.botstar.paginate({ + fn: this.botstar.listCmsEntities, + args: { + botId: this.botId, + }, + }); + + // Track if we've processed any entities + let hasEntities = false; + + // Collect entities to process newest first + const entities = []; + for await (const entity of results) { + hasEntities = true; + entities.push(entity); + } + + if (!hasEntities) { + return; + } + + // Process newest entities first + for (const entity of entities.reverse()) { + const meta = this.generateMeta(entity); + this.$emit(entity, meta); + } + },components/botstar/botstar.app.mjs (1)
82-104:paginate()has off-by-one and undefined-property risks
countstarts at 1, so withmax = 1the generator yields nothing.items?.lengthis assigned tototal, but if the API returns{ data: [...] }the loop condition misfires.args.paramsis mutated in-place, risking side effects for callers.Consider:
- limit: 100, + limit: args?.params?.limit ?? 100,and:
- let total, count = 1; + let pageSize; + let emitted = 0; ... - const items = await fn(args); + const items = await fn(args) ?? []; + pageSize = items.length; ... - if (max && ++count >= max) { + if (max && ++emitted >= max) {Finally, return early if
pageSizeis zero to avoid an infinite loop.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
components/botstar/actions/send-message/send-message.mjs(1 hunks)components/botstar/botstar.app.mjs(1 hunks)components/botstar/package.json(1 hunks)components/botstar/sources/common/base.mjs(1 hunks)components/botstar/sources/new-bot-created/new-bot-created.mjs(1 hunks)components/botstar/sources/new-bot-created/test-event.mjs(1 hunks)components/botstar/sources/new-cms-entity-created/new-cms-entity-created.mjs(1 hunks)components/botstar/sources/new-cms-entity-created/test-event.mjs(1 hunks)components/botstar/sources/new-cms-entity-item-created/new-cms-entity-item-created.mjs(1 hunks)components/botstar/sources/new-cms-entity-item-created/test-event.mjs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: pnpm publish
- GitHub Check: Verify TypeScript components
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (9)
components/botstar/sources/new-bot-created/test-event.mjs (1)
1-5: Add test-event fixture for “New Bot Created” source
The sample event object provides the expectedid,name, andteam_namefields. Ensure this fixture matches the actual BotStar API response schema for bot creation to avoid mismatches in your source component’s event emission.components/botstar/sources/new-cms-entity-item-created/test-event.mjs (1)
1-8: Add test-event fixture for “New CMS Entity Item Created” source
This object includes all necessary properties (name,status,entity_id,_id,short_description,photo). Verify that thephotoURL is accessible and that the field names align exactly with the CMS entity item payload returned by the BotStar API.components/botstar/sources/new-cms-entity-created/test-event.mjs (1)
1-26: Add test-event fixture for “New CMS Entity Created” source
The exported object accurately represents a CMS entity withid,name, and afieldsarray. Confirm that each field’sdata_typematches the API’s types (text,single_option,free_text,image) to ensure compatibility with downstream processing.components/botstar/sources/common/base.mjs (2)
1-2: Import BotStar app and default polling interval
Correctly imports thebotstar.app.mjsintegration and theDEFAULT_POLLING_SOURCE_TIMER_INTERVAL. Please verify that the relative path resolves properly in your build/runtime environment.
4-13: Define base props for all BotStar sources
Thebotstarprop and the timer interface are configured as expected. If users may need a custom polling interval, consider exposingintervalSecondsas a configurable prop with documentation.components/botstar/actions/send-message/send-message.mjs (1)
1-37: Well-structured BotStar message action componentThis new action component follows good practices for integration development. It provides clear descriptions for both the component itself and its properties, making it user-friendly. The implementation correctly handles authentication through the BotStar app object and follows the API structure as documented.
The run method properly exports a summary and returns the response, which is important for workflow visibility.
components/botstar/sources/new-cms-entity-item-created/new-cms-entity-item-created.mjs (2)
39-51: Good use of pagination for handling large datasetsThe implementation of the
runmethod uses thepaginatehelper from the BotStar app, which is excellent for handling potentially large sets of CMS entity items. This approach is more robust than fetching all items at once as it handles API limits gracefully.
20-28: Well-implemented dependent propertiesThe entityId property is correctly dependent on botId, using a callback function to pass the selected bot ID when retrieving available entities. This creates a good user experience by dynamically updating available options.
components/botstar/sources/new-cms-entity-created/new-cms-entity-created.mjs (1)
34-36: Good defensive programming with null/empty checkThe null check for
entities?.lengthis a good practice to prevent errors when no entities exist. This kind of defensive programming improves reliability.
GTFalcao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Resolves #13214
@vunguyenhung The BotStar API appears to have been updated since the test request was created. The test request should be:
And the instructions for getting the api token should be:
Summary by CodeRabbit
New Features
Chores